/* rehash --- a decentralised hash<->hash store
   Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>

   This file is part of rehash.

   rehash is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or (at
   your option) any later version.

   rehash is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with rehash.  If not, see <http://www.gnu.org/licenses/>. */

/**
 * @brief Searching for / inserting hashes in the DHT, without any caching
 * @author Maxime Devos
 *
 * Basically a rather thin wrapper around GNUNET_DHT_put
 * and GNUNET_DHT_get_start nicely documenting how to
 * encode / decode keys and values.
 */

#ifndef REHASH_DHT_H
#define REHASH_DHT_H

#include <gnunet/gnunet_dht_service.h>
#include "rehash_types.h"

#ifdef __cplusplus
extern "C"
{
#if 0
}
#endif
#endif

/**
 * Insert a hash -> hash mapping into the DHT
 *
 * @param handle handle to DHT service
 * @param key the key to store under, computed with
 *  REHASH_obfuscated_query_from_hash
 * @param desired_replication_level see GNUNET_DHT_put
 * @param options see GNUNET_DHT_put
 * @param size number of bytes in @a data
 * @param data the data to store, computed with
 *   REHASH_data_for_mapping
 * @param exp see GNUNET_DHT_put
 * @param cont see GNUNET_DHT_put
 * @param cont_cls see GNUNET_DHT_put
 * @return handle see GNUNET_DHT_PUT
 */
struct GNUNET_DHT_PutHandle *
REHASH_dht_put (struct GNUNET_DHT_Handle *handle,
                       const struct GNUNET_HashCode *key,
                       uint32_t desired_replication_level,
                       enum GNUNET_DHT_RouteOption options,
                       size_t size,
                       const void *data,
                       struct GNUNET_TIME_Absolute exp,
                       GNUNET_SCHEDULER_TaskCallback cont,
                       void *cont_cls);

/** Like GNUNET_DHT_get_start, but specialised to hash -> has mappings
 * and with less arguments.
 *
 * @param handle see GNUNET_DHT_get_start
 * @param key the key to look up, computed with
 * REHASH_obfuscated_query_from_hash
 * @param desired_replication_level see GNUNET_DHT_get_start
 * @param options see GNUNET_DHT_get_start
 * @param iter see GNUNET_DHT_get_start, decode data with
 *   REHASH_mapping_for_data
 * @param iter_cls see GNUNET_DHT_get_start
 * @return handle see GNUNET_DHT_get_start
 */
struct GNUNET_DHT_GetHandle *
REHASH_dht_get_start (struct GNUNET_DHT_Handle *handle,
		      const struct GNUNET_HashCode *key,
		      uint32_t desired_replication_level,
		      enum GNUNET_DHT_RouteOption options,
		      GNUNET_DHT_GetIterator iter,
		      void *iter_cls);

#if 0
{
#endif
#ifdef __cplusplus
}
#endif

#endif
